import http, { HttpResponse } from '../http'

// 等级弹窗数据类型
export interface AddLevelForm {
    /** @description 等级名称 */
    levelName: string
    /** @description 等级规则 */
    levelRule: number | null
    /** @description 等级背景 */
    levelBackground: string
}

// 等级配置列表类型
export interface LevelConfig extends AddLevelForm {
    /** @description 等级 id */
    id: number
    /** @description 是否为默认等级 */
    isDefault: boolean
    /** @description 会员类型 */
    levelType: number
}

// 请求结果 - 最终结果
interface MemberLevelResult extends HttpResponse {
    data: {
        list: Array<LevelConfig> | []
    }
}

// 获取会员等级列表
export const httpMemberLevelList = (): Promise<MemberLevelResult> => http('get', '/level/getMemberLevelList')

// 请求参数 - 新增会员等级
interface AddMemberLevelParams extends AddLevelForm {
    /** @description 是否为默认等级 1 默认等级 0 其他等级 */
    isDefault: number
}

// 新增会员等级
export const httpAddMemberLevel = (params: AddMemberLevelParams): Promise<HttpResponse> => http('post', '/level/addMemberLevel', params)

// 请求参数 - 更新会员等级
export interface UpdateMemberLevelParams extends AddLevelForm {
    /** @description 等级 id */
    id: number
}

// 修改会员等级
export const httpUpdateMemberLevel = (params: UpdateMemberLevelParams): Promise<HttpResponse> => http('post', '/level/updateMemberLevel', params)

// 删除会员等级
export const httpDeleteMemberLevel = (params: { id: number }): Promise<HttpResponse> => http('delete', '/level/deleteMemberLevel', params)
